<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/20 0020
 * Time: 下午 20:57
 */

namespace app\admin\controller;

use app\admin\model\Admin;
use think\Config;
use think\Cookie;
use think\Request;

class Login extends Base
{
    public function index(Request $request){
        if($request->post()){
            $data = $request->post();

            //判断字符
            $find   = ['select','update','delete'];
            foreach($find as $v){
                $pos = strpos($data['adminname'], $v);
                if($pos === true)return $this->ajaxResult(0);
            }

            $where['username'] = $data['adminname'];
            $where['password'] = md5(Config::get('salt').$data['adminpwd']);

            $admin = new Admin();
            $rs = $admin->getOne($where);

            if(empty($rs)) return $this->ajaxResult(0);

            Cookie::set('admin_id',$rs['id']);
            Cookie::set('admin_name',$rs['name']);

            return $this->ajaxResult(1);
        }
        return $this->fetch();
    }

}